﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Creational_Patterns.Builder_Pattern
{
    public class BuilderPattern : IPatternDemonstrate
    {
        public void StructuralCode()
        {
            // Create director and builders
            Director director = new Director();

            AbsBuilder b1 = new ConcreteBuilder1();
            AbsBuilder b2 = new ConcreteBuilder2();

            // Construct two products
            director.Construct(b1);
            Product p1 = b1.GetResult();
            p1.Show();

            director.Construct(b2);
            Product p2 = b2.GetResult();
            p2.Show();
        }

        public string PatternDescription()
        {
            string strDescription = @"
Definition
Separate the construction of a complex object from its representation so that the same construction process can create different representations.

Participants

    The classes and objects participating in this pattern are:

Builder  (VehicleBuilder)
·specifies an abstract interface for creating parts of a Product object
ConcreteBuilder  (MotorCycleBuilder, CarBuilder, ScooterBuilder)
·constructs and assembles parts of the product by implementing the Builder interface
·defines and keeps track of the representation it creates
·provides an interface for retrieving the product
Director  (Shop)
·constructs an object using the Builder interface
Product  (Vehicle)
·represents the complex object under construction. ConcreteBuilder builds the product's internal representation and defines the process by which it's assembled
·includes classes that define the constituent parts, including interfaces for assembling the parts into the final result";
            return strDescription;
        }

        public void RealWorldExample()
        {
            //THenu.TinyHourseLib.DesignPattern.Builder_Pattern.HouseBuilder hb = new THenu.TinyHourseLib.DesignPattern.Builder_Pattern.HouseBuilder();

            //THenu.TinyHourseLib.DesignPattern.Builder_Pattern.CarBuilder cb = new THenu.TinyHourseLib.DesignPattern.Builder_Pattern.CarBuilder();

            //THenu.TinyHourseLib.DesignPattern.Builder_Pattern.ActionDirector dir = new THenu.TinyHourseLib.DesignPattern.Builder_Pattern.ActionDirector();
            //dir.Construct(hb);

            //dir.Construct(cb);

            VehicleBuilder builder;

            // Create shop with vehicle builders
            Shop shop = new Shop();

            // Construct and display vehicles
            builder = new ScooterBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new CarBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();

            builder = new MotorCycleBuilder();
            shop.Construct(builder);
            builder.Vehicle.Show();
        }
    }
}
